<template>
      <div id="editpass">
            <el-dialog
                  title="修改密码"
                  :visible.sync="DialogData.show"
                  width="50%"
                  >
                        <div class="form">
                              <el-form :model="ruleForm" status-icon  ref="ruleForm" label-width="100px" class="demo-ruleForm">
                              <el-form-item label="原密码" prop="pass">
                              <el-input type="password" v-model="ruleForm.pass" autocomplete="off"></el-input>
                              </el-form-item>
                              <el-form-item label="新密码" prop="checkPass">
                              <el-input type="password" v-model="ruleForm.checkPass" autocomplete="off"></el-input>
                              </el-form-item>
                              <el-form-item label="确定密码" prop="age">
                              <el-input type="password" v-model="ruleForm.confirmPass"></el-input>
                              </el-form-item>
                             
                              </el-form>
                        </div>
                  <span slot="footer" class="dialog-footer">
                  <el-button @click="DialogData.show = false">取 消</el-button>
                  <el-button type="primary" @click="editPass">确 定</el-button>
                  </span>
                  </el-dialog>
      </div>
</template>

<script>
      export default {
            data() {
                  return {
                        dialogVisible: false,
                        ruleForm: {
                              pass: "",
                              checkPass: "",
                              confirmPass: ""
                        }
                  }
            },
            props: {
                  DialogData: Object
            },
            methods: {
                  async editPass() {
                        let { pass, checkPass, confirmPass } = this.ruleForm
                        if (!pass) {
                              this.$message.error("请输入原密码")
                              return false
                        } else if (checkPass != confirmPass && !checkPass) {
                              this.$message.error("两次输入的密码不一致,请重新输入")
                              return false
                        } else {
                              let token = localStorage.miniToken
                              let res = await this.$axios.post("/admin/user/pwdchange", {
                                    token,
                                    pwd: pass,
                                    password: checkPass
                              })
                              //console.log(res.data);
                              
                              let code = res.data.code 
                              if (code == 204) {
                                    this.$message.success("密码修改成功!")
                                    this.DialogData.show = false
                                    this.$router.push("/login")
                              } else {
                                   this.$message.error("密码修改失败!") 
                                   this.DialogData.show = false
                              }
                        }
                  }
            },
      }
</script>

<style lang="scss" scoped>

</style>